<template>
	<view class="bg-light" style="padding-bottom: 110rpx;">
		<tabsTop tabName="确认订单"></tabsTop>
		<!-- 自提选项 -->
		<view v-if="customerAddress" class="bg-white ml-2 p my-2 rounded-circle flex" style="width: 320rpx;">
			<view @click="handleMode" class="px-3 py-1 rounded-circle flex align-center"
				:class="!isSelfPickup?'bg-success':''" style="width: 100rpx;">
				<text class="font-sm" :class="!isSelfPickup?'text-white':'text-success'">商家配送</text>
			</view>
			<view @click="handleMode" class="px-3 py-1 rounded-circle flex align-center"
				:class="isSelfPickup?'bg-success':''" style="width: 100rpx;">
				<text class="font-sm" :class="isSelfPickup?'text-white':'text-success'">到店自提</text>
			</view>
		</view>
		<!-- 地址选择 -->
		<view v-if="!isSelfPickup" class="m-2 bg-white rounded-lg text-dark">
			<!-- 已选中地址 -->
			<view v-if="customerAddress" @click="handleAddress()" class="ml-2 py-2 flex justify-between align-center">
				<view class="flex flex-column">
					<text class="font">{{customerAddress.Address.replaceAll('/','')}}</text>
					<text class="font-md my-2 font-weight-bold">{{customerAddress.Address_Details}}</text>
					<text class="font">{{customerAddress.Name}} {{customerAddress.Phone}}</text>
				</view>
				<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
			</view>
			<!-- 未选中地址 -->
			<view v-else @click="handleAddress()" class="ml-2 py-2 flex justify-between align-center">
				<view class="flex flex-column">
					<text class="font">暂未获取到收货地址</text>
					<text class="font-lg my-2 font-weight-bold">请新建收货地址</text>
					<text class="font"></text>
				</view>
				<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
			</view>
			<!-- 配送方式 -->
			<view @click="handleDelivery()" class="flex py-2 align-center justify-between">
				<text class="ml-2 font">配送方式</text>
				<view>
					<text class="mr-2 font">快递 免运费</text>
					<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
				</view>
			</view>
		</view>
		<!-- 提货选择 -->
		<view v-else class="m-2 bg-white rounded-lg text-dark">
			<!-- 已选择提货人 -->
			<view class="ml-2 py-2 flex justify-between align-center">
				<view class="flex flex-column w-100">
					<text class="font-md font-weight-bold">鲜鸡蛋提货点</text>
					<text class="font my-2">黑龙江省哈尔滨市香坊区木材东街河畔花园</text>
					<view @click="handlePickupPerson()" class="mt-2 flex justify-between">
						<text class="font">提货人</text>
						<view v-if="defaultPerson">
							<text class="font font-weight-bold">{{defaultPerson.Name}} {{defaultPerson.Phone}}</text>
							<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
						</view>
						<view v-else>
							<text class="font font-weight-bold">去创建提货人信息</text>
							<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
						</view>
					</view>
				</view>
			</view>
			<!-- 提货时间 -->
			<view class="flex py-2 align-center justify-between">
				<text class="ml-2 font">提货时间</text>
				<view>
					<text class="mr-2 font text-success">请选择提货时间</text>
					<uni-icons type="right" class="mr-2" color="#828d96" size="16"></uni-icons>
				</view>
			</view>
		</view>
		<!-- 商品信息 -->
		<view class="mx-2 bg-white py-2 rounded-lg">
			<view v-for="(item,index) in Article" :key="index" class="flex mx-2" :class="index!=0?'':'mt-2'">
				<view class="flex-shrink rounded overflow-hidden" style="width: 180rpx; height: 180rpx;">
					<image :src="Domain_IMG+item.Picture_URL" class="img" mode=""></image>
				</view>
				<view class="ml-2 flex flex-column justify-between w-100">
					<text>{{item.Article_Name}}</text>
					<view class="flex justify-between">
						<money :money="item.Sales_Unit_Price"></money>
						<counter @Count="handleCount($event,item)" :num="item.Quantity"></counter>
					</view>
				</view>
			</view>
		</view>
		<!-- 总计 -->
		<view class="m-2 py-2 bg-white rounded-lg">
			<view class="mx-2 flex flex-column">
				<!-- 商品总价 -->
				<view class="flex mb-2 justify-between">
					<view><!-- 左 -->
						<text class="font text-dark">商品总价</text>
						<text class="ml-1 font text-muted">共2件商品</text>
					</view>
					<view><!-- 右 -->
						<text class="font text-dark font-weight-bold">￥{{Amount}}</text>
					</view>
				</view>
				<!-- 优惠券 -->
				<view @click="handleCoupon" class="flex my-2 justify-between">
					<view><!-- 左 -->
						<text class="font text-dark">优惠券</text>
					</view>
					<view><!-- 右 -->
						<text class="font text-muted">暂无可用</text>
						<uni-icons type="right" color="#828d96" size="16"></uni-icons>
					</view>
				</view>
				<!-- 积分 -->
				<!-- <view class="flex py-2 justify-between border-bottom border-light-secondary">
					<view>
						<text class="font text-dark">小康币</text>
						<text class="ml-1 font text-muted">共100小康币</text>
					</view>
					<view>
						<text class="font text-success font-weight-bold">-￥1.00</text>
						<uni-icons type="right" color="#828d96" size="16"></uni-icons>
					</view>
				</view> -->
				<!-- 合计 -->
				<view class="flex mt-2 justify-end">
					<view>
						<text class="font text-dark">合计：</text>
						<text class="ml-1 font font-weight-bold text-dark">￥{{total}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 支付方式 -->
		<view v-for="(item,index) in pay" :key="index" @click="handlePay(item)"
			class="mx-2 py-2 bg-white rounded-lg flex justify-between">
			<view class="ml-2 flex align-center">
				<uni-icons fontFamily="iconfont" :color="item.Color" size="20">{{item.Icon}}</uni-icons>
				<text class="font ml-2 text-dark">{{item.Name}}</text>
			</view>
			<view class="mr-2">
				<uni-icons v-if="!item.isSelect" type="circle" :color="item.Color" size="20"></uni-icons>
				<uni-icons v-else type="checkbox-filled" :color="item.Color" size="20"></uni-icons>
			</view>
		</view>
		<!-- 买家留言 -->
		<view class="m-2 py-2 bg-white flex rounded-lg">
			<text class="ml-2 font flex-shrink pr-4">买家留言</text>
			<textarea v-model="Sales_Message" class="font text-right w-100 mr-2"
				placeholder-class="text-muted text-right" placeholder="留言建议提前协商 (250字以内) " auto-height></textarea>
		</view>
		<!-- 底部提交 -->
		<view class="fixed-bottom shadow flex align-center justify-between bg-white" style="height: 110rpx;">
			<view class="ml-3 flex align-end">
				<text class="font-lg">应付：</text>
				<text class="font-sm text-success">￥</text>
				<text class="font-lg text-success">{{total}}</text>
			</view>
			<view @click="submit" class="mr-3 px-3 py-2 rounded-circle flex align-center"
				:style="{backgroundColor:pay.filter(i=>i.isSelect)[0].Color}">
				<text class="text-white font">{{pay.filter(i=>i.isSelect)[0].Name}}</text>
			</view>
		</view>
		<!-- 地址弹窗 -->
		<popUp :show="isAddress" @scrollTolower="onAddressScollBottom" title="请选择收获地址" :button="['新增地址']" Height="50"
			@Close="handleAddress" @submit1="handleAddressAdd">
			<view class="mx-2 py-2">
				<!-- 地址详情 -->
				<view v-for="(item,index) in tableDataAddress" :key="index"
					class="bg-white mb-2 py-2 w-100 flex align-center rounded-lg">
					<!-- 信息 -->
					<view class="flex w-100 align-center" @click="selectAddress(item)">
						<view class="flex-shrink mx-2">
							<uni-icons v-if="item.Address_SerialNumber!=customerAddress.Address_SerialNumber"
								type="circle" color="#28a745" size="20"></uni-icons>
							<uni-icons v-else type="checkbox-filled" color="#28a745" size="20"></uni-icons>
						</view>
						<view class="w-100 flex flex-column">
							<text class="font text-dark">{{Address(item.Address,item.Address_Details)}}</text>
							<text class="font mt-2 text-muted">{{item.Name}} {{item.Phone}}</text>
						</view>
					</view>
					<!-- 修改 -->
					<view @click="handleAddressEdit(item.Address_SerialNumber)" class="flex-shrink mr-2">
						<uni-icons fontFamily="iconfont" color="#828d96" size="20">{{'\ue8cf'}}</uni-icons>
					</view>
				</view>
			</view>
		</popUp>
		<!-- 提货人 -->
		<popUp :show="isPickupPerson" @scrollTolower="onPickupScollBottom" title="请选提货人" @submit1="pickupPersonAdd"
			:button="['新增提货人']" Height="50" @Close="handlePickupPerson">
			<view class="pt-2 bg-white flex flex-column" v-for="(item,index) in tableDataPickup" :key="index">
				<view class="pb-2 flex justify-between align-center" @click="selectpickupPerson(item)">
					<view class="flex ml-4">
						<uni-icons @click.stop="pickupPersonEdit(item.Picker_SerialNumber)" fontFamily="iconfont"
							color="#828d96" size="20">{{'\ue8cf'}}</uni-icons>
						<text class="font ml-2">{{item.Name}}，{{item.Phone}}</text>
					</view>
					<view class="flex-shrink mr-4">
						<uni-icons v-if="item.Picker_SerialNumber!=defaultPerson.Picker_SerialNumber" type="circle"
							color="#28a745" size="20"></uni-icons>
						<uni-icons v-else type="checkbox-filled" color="#28a745" size="20"></uni-icons>
					</view>
				</view>
			</view>
		</popUp>
		<!-- 配送方式 -->
		<popUp :show="isDelivery" title="请选择配送方式" Height="40" @Close="handleDelivery">
			<view class="pt-2 bg-white flex flex-column">
				<view class="pb-2 flex justify-between align-center">
					<text class="font ml-4">同城配送</text>
					<view class="flex-shrink mr-4">
						<uni-icons v-if="false" type="circle" color="#28a745" size="20"></uni-icons>
						<uni-icons v-else type="checkbox-filled" color="#28a745" size="20"></uni-icons>
					</view>
				</view>
				<view class="pb-2 flex justify-between align-center">
					<text class="font ml-4">快递 免运费</text>
					<view class="flex-shrink mr-4">
						<uni-icons v-if="false" type="circle" color="#28a745" size="20"></uni-icons>
						<uni-icons v-else type="checkbox-filled" color="#28a745" size="20"></uni-icons>
					</view>
				</view>
			</view>
		</popUp>
		<!-- 优惠券 -->
		<popUp :show="isCoupon" title="请选择优惠券" :button="['不使用优惠券','确认']" Height="70" @Close="handleCoupon">
			<view id="fixed" class="pb-1 bg-white flex flex-column">
				<!-- 导航栏 -->
				<view class="bg-white flex align-center">
					<!-- 搜索框 -->
					<view class="w-100 mx-4 py-1 rounded-circle bg-light flex justify-between align-center">
						<input class="mx-2 font-sm w-100" type="text" placeholder-class="text-muted font-sm"
							placeholder="请输入优惠码" />
					</view>
					<!-- 兑换 -->
					<text class="pr-4 flex-shrink font text-success">兑换</text>
				</view>
				<!-- 选项卡 -->
				<view class="bg-white flex  border-bottom border-light">
					<view class="w-100 flex justify-center">
						<text class="text-center font py-1 border-bottom border-success"
							style="border-width: 5rpx; box-sizing: border-box;">可用</text>
					</view>
					<view class="w-100 flex justify-center">
						<text class="text-center font py-1 border-bottom border-success"
							style="border-width: 5rpx; box-sizing: border-box;">不可以</text>
					</view>
				</view>
				<view class="mt-1">
					<text class="ml-2 font-sm">请选择优惠券</text>
				</view>
			</view>
			<scroll-view @scrolltolower="onCouponScollBottom" class="bg-light" scroll-y="true" style="height: 72%">
				<view class="flex align-center mt-2" v-for="(item,index) in tableDataCoupon" :key="index"
					@click="selectCoupon(item)">
					<view class="flex-shrink mx-2">
						<uni-icons v-if="item.Coupon_SerialNumber != Coupon.Coupon_SerialNumber" type="circle"
							color="#28a745" size="20"></uni-icons>
						<uni-icons v-else type="checkbox-filled" color="#28a745" size="20"></uni-icons>
					</view>
					<coupon :couponName="item.Coupon_Scheme_Name" :couponRule="item.Coupon_Scheme_Rule"
						:Min_Amount="item.Min_Amount" :Preferential="item.Preferential"></coupon>
				</view>
			</scroll-view>
		</popUp>
		<!-- 外部跳转 -->
	</view>
</template>

<script>
	const app = getApp();
	import tabsTop from "@/components/tabs/tabs-top.vue";
	import money from "@/components/tool/money.vue";
	import counter from "@/components/tool/counter.vue";
	import popUp from "@/components/tabs/pop-up.vue";
	import coupon from "@/components/tool/coupon.vue"
	import WebSocketIO from "@/static/js/WebSocket.js"
	import {
		accAdd,
		accMul
	} from "@/static/js/GeneralUtil.js"
	import {
		NowTime
	} from "@/static/js/DateUtil.js"
	import {
		getPickerAllAction,
		getAddressAllAction
	} from "@/api/delivery.js"
	import {
		getSalesCouponAction
	} from "@/api/coupon.js"
	import {
		setAsynChronousAdd,
		getAddAction
	} from "@/api/global.js"
	import {
		WeChatDefray,
		CheckStock
	} from "@/api/pay.js"
	export default {
		components: {
			tabsTop, //顶部标题组件
			money, //钱样式
			popUp, //上移弹出啊
			counter, //计数器
			coupon
		},
		data() {
			return {
				Domain_IMG: app.globalData.Domain_IMG, //商品图片地址
				isSelfPickup: false, //到店自提
				//自提开始
				isPickupPerson: false, //提货人弹窗
				defaultPerson: null, //已选自提人
				tableDataPickup: [], // 存放自提人
				formPickup: { //自提人查询地址
					page: 1,
					limit: 10,
					Open_ID: app.globalData.Open_ID,
					App_ID: app.globalData.App_ID,
				},
				totalPickup: 0, //自提人总数
				isReachPickup: true, //判断自提人是否查询完毕
				//配送开始
				isDelivery: false, //配送弹窗
				//优惠券开始
				isCoupon: false, //优惠券弹窗
				formCoupon: { //优惠券查询
					page: 1,
					limit: 10,
					Open_ID: app.globalData.Open_ID,
					App_ID: app.globalData.App_ID,
					Enterprise_Info_SerialNumber: app.globalData.Enterprise_Info_SerialNumber,
					Article_SerialNumber: ""
				},
				totalCoupon: 0, //优惠券条数
				isReachCoupon: true,
				Coupon: null, //已选优惠券
				tableDataCoupon: [], //优惠券数据
				//地址开始
				customerAddress: null, //已选地址
				isAddress: false, //地址弹窗
				formAddress: { //查询地址
					page: 1,
					limit: 10,
					Open_ID: app.globalData.Open_ID,
					App_ID: app.globalData.App_ID,
				},
				totalAddress: 0, //地址总数
				tableDataAddress: [], //存放地址
				isReachAddress: false, //判断地址是否查询完毕

				Article: [
					// 	{
					// 	Article_Name: "云海川大米（红袋、蓝袋）5kg/袋",
					// 	Category_Name: "普通实物商品",
					// 	Article_SerialNumber: "A00000000000001",
					// 	Picture_URL: "/C_3813482658_1.jpg",
					// 	Article_Specifications_SerialNumber: "A04000000000060",
					// 	Sales_Unit_Price: "98",
					// 	Sales_Unit_Price_Stock_SerialNumber: "H01100000000583",
					// 	Sign: "无货货主",
					// 	Stock_Remain: "100",
					// 	Stock_Sell: "0",
					// 	Quantity:1,
					// 	Unit_Price: "98.00"
					// },
				], //商品信息
				loading: false, //节流
				Amount: "0", //总金额
				Quantity: 1, //总数量
				total: "0", //合计
				Sales_Message: '',
				pay: [{
						Name: '微信支付',
						Icon: '\ue650',
						isSelect: true,
						Color: '#28a745'
					},
					// {
					// 	Name:'储值支付',
					// 	Icon:'\ue695',
					// 	isSelect:false,
					// 	Color:'#ffc107'
					// },
					{
						Name: '支付宝支付',
						Icon: '\ue65f',
						isSelect: false,
						Color: '#007bff'
					},
				],
				html: ''
			}
		},
		onShow() {
			//获取本地存储地址
			if (uni.getStorageSync("customerAddress")) {
				this.customerAddress = uni.getStorageSync("customerAddress")
			}
			if (uni.getStorageSync("defaultPerson")) {
				this.defaultPerson = uni.getStorageSync("defaultPerson")
			}
			if (this.isAddress) { //地址查询
				this.formAddress.page = 1;
				this.getAddressAction(this.formAddress)
			}
			if (this.isPickupPerson) { //自提人查询
				this.formPickup.page = 1;
				this.getPickupPerson(this.formPickup)
			}
		},
		onLoad(e) {
			this.Article = JSON.parse(decodeURIComponent(e.good));
			this.Article.forEach(item => {
				this.Amount = accAdd(this.Amount, accMul(item.Quantity, item.Sales_Unit_Price))
				this.Quantity = this.Quantity + item.Quantity
			})
			this.total = this.Amount
		},
		computed: {
			Address() {
				return function(str1, str2) {
					try {
						return str1.replaceAll('/', '') + str2;
					} catch (e) {
						return "";
					}
				}
			},
		},
		methods: {
			handleMode() { //配送or自提
				this.isSelfPickup = !this.isSelfPickup
			},
			handleCount(e, item) { //选择数量
				item.Quantity = e
				this.Amount = accMul(item.Quantity, item.Sales_Unit_Price)
				this.total = this.Amount
			},
			/**
			 * 地址开始
			 */
			handleAddress() { //地址弹窗打开/关闭
				this.isAddress = !this.isAddress
				if (this.isAddress) {
					this.getAddressAction(this.formAddress)
				}
			},
			async getAddressAction(data, onReach = false) { //查询地址
				if (!this.loading) {
					this.loading = true;
					uni.showLoading({
						title: "加载中...",
					});
					const res = await getAddressAllAction(data);
					if (res.Status == 'success') {
						//判断是否重新开始查询
						if (!onReach) {
							this.formAddress.page = 1
							this.tableDataAddress = [];
						}
						this.tableDataAddress.push(...res.tableData);
						this.totalAddress = Number(res.limit);
					}
					uni.hideLoading();
					this.loading = false;
				}
			},
			onAddressScollBottom() { //地址滚动到底部
				if (this.isReachAddress) {
					if (this.tableDataAddress.length < this.totalAddress) {
						this.formAddress.page++;
						this.getAddressAction(this.formAddress, true)
					} else {
						this.isReachAddress = false;
					}
				}
			},
			selectAddress(item) { //选择地址
				this.customerAddress = item
				this.isAddress = false
				this.tableDataAddress = [];
				this.formAddress.page = 1
			},
			handleAddressAdd() { //地址跳转添加
				uni.navigateTo({
					url: '/pages/delivery/addressAdd'
				})
			},
			handleAddressEdit(Address_SerialNumber) { //地址跳转添加
				uni.navigateTo({
					url: '/pages/delivery/addressEdit?Address_SerialNumber=' + Address_SerialNumber
				})
			},
			/**
			 * 提货人
			 */
			handlePickupPerson() { //提货人弹窗打开/关闭
				this.isPickupPerson = !this.isPickupPerson
				if (this.isPickupPerson) {
					this.getPickupPerson(this.formPickup);
				}
			},
			async getPickupPerson(data, onReach = false) {
				if (!this.loading) {
					this.loading = true;
					uni.showLoading({
						title: "加载中...",
					});
					const res = await getPickerAllAction(data);
					if (res.Status == 'success') {
						//判断是否重新开始查询
						if (!onReach) {
							this.formPickup.page = 1
							this.tableDataPickup = [];
						}
						this.tableDataPickup.push(...res.tableData);
						this.totalPickup = Number(res.limit);
					}
					uni.hideLoading();
					this.loading = false;
				}
			},
			onPickupScollBottom() { //到底刷新数据
				if (this.isReachPickup) { //是否有剩余数据
					if (this.tableDataAddress.length < this.totalPickup) {
						this.formPickup.page++;
						this.getPickerAllAction(this.formPickup, true)
					} else {
						this.isReachPickup = false;
					}
				}
			},
			pickupPersonAdd() { //添加
				uni.navigateTo({
					url: "/pages/delivery/pickupPersonAdd"
				})
			},
			pickupPersonEdit(Picker_SerialNumber) { //修改
				uni.navigateTo({
					url: "/pages/delivery/pickupPersonEdit?Picker_SerialNumber=" + Picker_SerialNumber
				})
			},
			selectpickupPerson(item) { //选择
				this.defaultPerson = item
				this.isPickupPerson = false
				this.tableDataPickup = [];
				this.formPickup.page = 1
			},
			/**
			 * 
			 */
			handleDelivery() { //配送弹窗打开/关闭
				this.isDelivery = !this.isDelivery
			},
			handleCoupon() { //优惠券弹窗打开/关闭
				this.isCoupon = !this.isCoupon
				if (this.isCoupon) {
					let arr = [];
					this.Article.forEach(item => {
						arr.push(item.Article_SerialNumber)
					})
					this.formCoupon.Article_SerialNumber = JSON.stringify(arr)
					this.getSalesCoupon(this.formCoupon)
				}

			},
			selectCoupon(item) { //选中优惠券
				this.Coupon = item;
				this.isCoupon = false;
				this.totalCoupon = [];
				this.formCoupon.page = 1;
			},
			onCouponScollBottom() {
				if (this.isCoupon) { //是否有剩余数据
					if (this.tableDataCoupon.length < this.totalCoupon) {
						this.formCoupon.page++;
						this.getSalesCoupon(this.formCoupon, true)
					} else {
						this.isCoupon = false;
					}
				}
			},
			async getSalesCoupon(data, onReach = false) {
				if (!this.loading) {
					this.loading = true;
					uni.showLoading({
						title: "加载中...",
					});
					const res = await getSalesCouponAction(data);
					if (res.Status == 'success') {
						//判断是否重新开始查询
						if (!onReach) {
							this.formCoupon.page = 1
							this.tableDataCoupon = [];
						}
						this.tableDataCoupon.push(...res.tableData);
						this.totalCoupon = Number(res.limit);
					}
					console.log(res);
					uni.hideLoading();
					this.loading = false;
				}
			},
			handlePay(item) { //选中支付方式
				this.pay.forEach(item => {
					item.isSelect = false
				})
				item.isSelect = true
			},
			async InventoryInspection(Sales_Unit_Price_Stock_SerialNumber, Quantity, callback) {
				callback(await CheckStock({
					Data: JSON.stringify([{
						Sales_Unit_Price_Stock_SerialNumber,
						Quantity
					}])
				}))
			},
			async submit() { //提交订单新
				if (!this.loading) {
					// this.loading = true
					// uni.showLoading({
					// 	title: "加载中...",
					// });
					let sales_order = {
						Sales_Order_SerialNumber: '',
						Store_SerialNumber: this.Article[0].Store_SerialNumber,
						Sales_Address: this.customerAddress.Address + this.customerAddress.Address_Details,
						Sales_Contacts: this.customerAddress.Name,
						Sales_Phone: this.customerAddress.Phone,
						Sales_Message: this.Sales_Message,
						Sales_Date: NowTime(),
						Open_ID: app.globalData.Open_ID,
						App_ID: app.globalData.App_ID,
						Sales_Amount: this.total,
						Collection_Amount: 0,
						Delivery_Amount: 0,
						Receive_Type: 0,
						Refund_Type: 0,
						Enterprise_Info_SerialNumber: app.globalData.Enterprise_Info_SerialNumber,
						Children: {
							sales_order_detail: [{
								Sales_Order_Detail_SerialNumber: '',
								Sales_Order_SerialNumber: '',
								Sales_Unit_Price_Stock_SerialNumber: this.Article[0]
									.Sales_Unit_Price_Stock_SerialNumber,
								Article_SerialNumber: this.Article[0].Article_SerialNumber,
								Article_Specifications_SerialNumber: this.Article[0]
									.Article_Specifications_SerialNumber,
								Sign: this.Article[0].Sign,
								Quantity: this.Article[0].Quantity,
								Unit_Price: this.Article[0].Unit_Price,
								Sales_Unit_Price: this.Article[0].Sales_Unit_Price,
								Amount: this.Amount,
								Receive_Type: 0,
								Refund_Type: 0,
								Enterprise_Info_SerialNumber: app.globalData.Enterprise_Info_SerialNumber,
							}]
						},
					}
					this.websocket = new WebSocketIO('submitSalesOrder' + app.globalData.Open_ID, this.$websocketUrl,
						10000)
					this.websocket.connectSocketInit();
					uni.$on("socketMsg", (res) => {
						res = JSON.parse(res)
						// this.websocket.closeSocket();   
						// if(res.Status=="success"){
						// 	this.Pay(res.Data)
						// }
					})
					//监听收到的数据
					for (var i = 0; i < 10000; i++) {
						console.log(i);
						sales_order.Sales_Message = i;
						await setAsynChronousAdd({
							Data: JSON.stringify({
								Add: {
									sales_order: [sales_order]
								},
								Name: 'submitSalesOrder' + app.globalData.Open_ID,
							}),
							Open_ID: app.globalData.Open_ID
						})
					}
				}
			},
			// submit(){//提交订单
			// 	if(!this.loading){
			// 		this.loading = true
			// 		uni.showLoading({
			// 			title: "加载中...",
			// 		});
			// 		let sales_order = {
			// 			Sales_Order_SerialNumber:'',
			// 			Store_SerialNumber:this.Article[0].Store_SerialNumber,
			// 			Sales_Address:this.customerAddress.Address+this.customerAddress.Address_Details,
			// 			Sales_Contacts:this.customerAddress.Name,
			// 			Sales_Phone:this.customerAddress.Phone,
			// 			Sales_Message:this.Sales_Message,
			// 			Sales_Date:NowTime(),
			// 			Open_ID:app.globalData.Open_ID,
			// 			App_ID:app.globalData.App_ID,
			// 			Sales_Amount:this.total,
			// 			Collection_Amount:0,
			// 			Delivery_Amount:0,
			// 			Receive_Type:0,
			// 			Refund_Type:0,
			// 			Enterprise_Info_SerialNumber:app.globalData.Enterprise_Info_SerialNumber,
			// 			Children:{
			// 				sales_order_detail:[{
			// 					Sales_Order_Detail_SerialNumber:'',
			// 					Sales_Order_SerialNumber:'',
			// 					Sales_Unit_Price_Stock_SerialNumber:this.Article[0].Sales_Unit_Price_Stock_SerialNumber,
			// 					Article_SerialNumber:this.Article[0].Article_SerialNumber,
			// 					Article_Specifications_SerialNumber:this.Article[0].Article_Specifications_SerialNumber,
			// 					Sign:this.Article[0].Sign,
			// 					Quantity:this.Article[0].Quantity,
			// 					Unit_Price:this.Article[0].Unit_Price,
			// 					Sales_Unit_Price:this.Article[0].Sales_Unit_Price,
			// 					Amount:this.Amount,
			// 					Receive_Type:0,
			// 					Refund_Type:0,
			// 					Enterprise_Info_SerialNumber:app.globalData.Enterprise_Info_SerialNumber,
			// 				}]
			// 			},
			// 		}
			// 		this.InventoryInspection(this.Article[0].Sales_Unit_Price_Stock_SerialNumber,this.Article[0].Quantity,async ({Status})=>{
			// 			if(Status == 'success'){
			// 				const res = await getAddAction({
			// 					Data:JSON.stringify({sales_order:[sales_order]}),
			// 					Open_ID:app.globalData.Open_ID
			// 				})
			// 				if(res.Status=='success'){
			// 					this.Pay(res.Data)
			// 				}
			// 			} else if(Status == 'insufficient'){
			// 				uni.showToast({title: '库存不足!',icon: 'error',})
			// 				this.loading = false
			// 				uni.hideLoading();
			// 			}
			// 		})
			// 	}
			// },
			async Pay(Sales_Order_SerialNumber) {
				let Collection_Type
				if (this.pay.filter(i => i.isSelect)[0].Name == '微信支付') {
					Collection_Type = "微信支付";
				} else if (this.pay.filter(i => i.isSelect)[0].Name == '储值支付') {
					Collection_Type = "储值账户";
				} else if (this.pay.filter(i => i.isSelect)[0].Name == '支付宝支付') {
					Collection_Type = "支付宝支付";
				}
				const res = await WeChatDefray({
					Sales_Order_SerialNumber,
					Collection_Type,
				})
				if (Collection_Type == '微信支付' && res.result_msg == "SUCCESS") {
					let appId = res.sdk_appid;
					let timeStamp = res.sdk_timestamp + '';
					let nonceStr = res.sdk_noncestr;
					let packageX = res.sdk_package;
					let signType = res.sdk_signtype;
					let paySign = res.sdk_paysign;
					uni.hideLoading();
					uni.requestPayment({
						provider: 'wxpay',
						appId: appId,
						timeStamp: timeStamp,
						nonceStr: nonceStr,
						package: packageX,
						signType: signType,
						paySign: paySign,
						success: function(res) {
							uni.showToast({
								title: '支付成功!',
								icon: 'success',
								success() {
									console.log('支付成功');
								}
							})
						},
						fail: function(err) {
							uni.showToast({
								title: '已取消！',
								icon: 'error'
							})
						},
						//调起支付后打开懒加载
						complete: () => {
							this.loading = false
							uni.hideLoading();
						}
					})
				} else if (Collection_Type == '支付宝支付' && res.Status == "success") {
					this.loading = false
					uni.hideLoading();
					uni.setStorageSync('AliPay', res.Url)
					uni.navigateTo({
						url: '/pages/index/AliPay'
					})
				} else {
					this.loading = false
					uni.hideLoading();
					uni.showToast({
						title: '提交失败，请重试！',
						icon: 'error'
					})
				}
			}
		}
	}
</script>

<style>

</style>